$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'cus/tpmuser/list',
        datatype: "json",
        colModel: [			
			{ label: 'FADNUMBER', name: 'fadnumber', index: 'FADNUMBER', width: 80 }, 			
			{ label: 'FAGENTUSER', name: 'fagentuser', index: 'FAGENTUSER', width: 80 }, 			
			{ label: 'FBACKUPEMAIL', name: 'fbackupemail', index: 'FBACKUPEMAIL', width: 80 }, 			
			{ label: 'FCELL', name: 'fcell', index: 'FCELL', width: 80 }, 			
			{ label: 'FCONTROLUNITID', name: 'fcontrolunitid', index: 'FCONTROLUNITID', width: 80 }, 			
			{ label: 'FCREATETIME', name: 'fcreatetime', index: 'FCREATETIME', width: 80 }, 			
			{ label: 'FCREATORID', name: 'fcreatorid', index: 'FCREATORID', width: 80 }, 			
			{ label: 'FCUSTOMERID', name: 'fcustomerid', index: 'FCUSTOMERID', width: 80 }, 			
			{ label: 'FDEFAULTLOCALE', name: 'fdefaultlocale', index: 'FDEFAULTLOCALE', width: 80 }, 			
			{ label: 'FDEFORGUNITID', name: 'fdeforgunitid', index: 'FDEFORGUNITID', width: 80 }, 			
			{ label: 'FDESCRIPTION_L1', name: 'fdescriptionL1', index: 'FDESCRIPTION_L1', width: 80 }, 			
			{ label: 'FDESCRIPTION_L2', name: 'fdescriptionL2', index: 'FDESCRIPTION_L2', width: 80 }, 			
			{ label: 'FDESCRIPTION_L3', name: 'fdescriptionL3', index: 'FDESCRIPTION_L3', width: 80 }, 			
			{ label: 'FEFFECTIVEDATE', name: 'feffectivedate', index: 'FEFFECTIVEDATE', width: 80 }, 			
			{ label: 'FEMAIL', name: 'femail', index: 'FEMAIL', width: 80 }, 			
			{ label: 'FERRCOUNT', name: 'ferrcount', index: 'FERRCOUNT', width: 80 }, 			
			{ label: 'FFORBIDDEN', name: 'fforbidden', index: 'FFORBIDDEN', width: 80 }, 			
			{ label: 'FGROUPID', name: 'fgroupid', index: 'FGROUPID', width: 80 }, 			
			{ label: 'FHOMEPHONE', name: 'fhomephone', index: 'FHOMEPHONE', width: 80 }, 			
			{ label: 'fid', name: 'fid', index: 'FID', width: 50, key: true },
			{ label: 'FINVALIDATIONDATE', name: 'finvalidationdate', index: 'FINVALIDATIONDATE', width: 80 }, 			
			{ label: 'FISAUTHENADMIN', name: 'fisauthenadmin', index: 'FISAUTHENADMIN', width: 80 }, 			
			{ label: 'FISBIZADMIN', name: 'fisbizadmin', index: 'FISBIZADMIN', width: 80 }, 			
			{ label: 'FISCHANGEDPW', name: 'fischangedpw', index: 'FISCHANGEDPW', width: 80 }, 			
			{ label: 'FISDELETE', name: 'fisdelete', index: 'FISDELETE', width: 80 }, 			
			{ label: 'FISLOCKED', name: 'fislocked', index: 'FISLOCKED', width: 80 }, 			
			{ label: 'FISREGISTER', name: 'fisregister', index: 'FISREGISTER', width: 80 }, 			
			{ label: 'FLASTUPDATETIME', name: 'flastupdatetime', index: 'FLASTUPDATETIME', width: 80 }, 			
			{ label: 'FLASTUPDATEUSERID', name: 'flastupdateuserid', index: 'FLASTUPDATEUSERID', width: 80 }, 			
			{ label: 'FLOCKEDTIME', name: 'flockedtime', index: 'FLOCKEDTIME', width: 80 }, 			
			{ label: 'FLOGINAUTHORWAY', name: 'floginauthorway', index: 'FLOGINAUTHORWAY', width: 80 }, 			
			{ label: 'FMAINROLEID', name: 'fmainroleid', index: 'FMAINROLEID', width: 80 }, 			
			{ label: 'FNAMEPINYIN', name: 'fnamepinyin', index: 'FNAMEPINYIN', width: 80 }, 			
			{ label: 'FNAMESHORTPINYIN', name: 'fnameshortpinyin', index: 'FNAMESHORTPINYIN', width: 80 }, 			
			{ label: 'FNAME_L1', name: 'fnameL1', index: 'FNAME_L1', width: 80 }, 			
			{ label: 'FNAME_L2', name: 'fnameL2', index: 'FNAME_L2', width: 80 }, 			
			{ label: 'FNAME_L3', name: 'fnameL3', index: 'FNAME_L3', width: 80 }, 			
			{ label: 'FNUMBER', name: 'fnumber', index: 'FNUMBER', width: 80 }, 			
			{ label: 'FOFFICEPHONE', name: 'fofficephone', index: 'FOFFICEPHONE', width: 80 }, 			
			{ label: 'FPASSWORD', name: 'fpassword', index: 'FPASSWORD', width: 80 }, 			
			{ label: 'FPERSONID', name: 'fpersonid', index: 'FPERSONID', width: 80 }, 			
			{ label: 'FPINYIN', name: 'fpinyin', index: 'FPINYIN', width: 80 }, 			
			{ label: 'FPWDHISSTR', name: 'fpwdhisstr', index: 'FPWDHISSTR', width: 80 }, 			
			{ label: 'FPWEFFECTIVEDATE', name: 'fpweffectivedate', index: 'FPWEFFECTIVEDATE', width: 80 }, 			
			{ label: 'FREFERID', name: 'freferid', index: 'FREFERID', width: 80 }, 			
			{ label: 'FSECURITYID', name: 'fsecurityid', index: 'FSECURITYID', width: 80 }, 			
			{ label: 'FSHORTPINYIN', name: 'fshortpinyin', index: 'FSHORTPINYIN', width: 80 }, 			
			{ label: 'FSUPPLIERID', name: 'fsupplierid', index: 'FSUPPLIERID', width: 80 }, 			
			{ label: 'FTYPE', name: 'ftype', index: 'FTYPE', width: 80 }			
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		TPmUser: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.TPmUser = {};
		},
		update: function (event) {
			var fid = getSelectedRow();
			if(fid == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(fid)
		},
		saveOrUpdate: function (event) {
			var url = vm.TPmUser.fid == null ? "cus/tpmuser/save" : "cus/tpmuser/update";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.TPmUser),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var fids = getSelectedRows();
			if(fids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "cus/tpmuser/delete",
                    contentType: "application/json",
				    data: JSON.stringify(fids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(fid){
			$.get(baseURL + "cus/tpmuser/info/"+fid, function(r){
                vm.TPmUser = r.TPmUser;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		}
	}
});